package com.chris.utils;

import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class  LogUtil {
    static Logger  logger;
    static FileHandler fileHandler;
    static SimpleFormatter sm;
    static {
        logger = Logger.getLogger("com.chris.serve");
        URL resource = LogUtil.class.getResource("/out.log");
        String substring = resource.getPath().substring(1);
        System.out.println(substring);
        try {
            fileHandler = new FileHandler(substring,true);
            fileHandler.setEncoding("UTF-8");
            System.out.println("test222");
        } catch (IOException e) {
            e.printStackTrace();
        }
        sm = new SimpleFormatter();
        fileHandler.setFormatter(sm);
        logger.addHandler(fileHandler);
    }
    public static void log(String msg,Throwable e){
        logger.log(Level.SEVERE,"test");
        logger.log (Level.SEVERE,msg,e);
        fileHandler.close();
    }
}
